<?php


namespace app\common\model;

class Settings extends Base
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'ddt_settings';

    function getOneSetting($condition){
        $where = [
            ['setg','=',$condition['setg']],
            ['key','=',$condition['setg']],
        ];
        return $this->where($where)->find();
    }

    // 获取列表
    function get_list($cond)
    {
        $where = null;
        if(!empty($cond['setg'])){
            $where[] = ['setg','=',$cond['setg']];
        }
        if(!empty($cond['key'])){
            $where[] = ['key','=',$cond['setg']];
        }
        $rs = $this
            ->where($where)
            ->select();
        return $rs;
    }

	/**
	 * @title 获取指定配置
	 * @param $setg
	 * @return int|void
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	function getsetg($setg){
		$data = $this->where('setg','=',$setg)->select()->toArray();
		$data = array_column($data,'value','key');
		return $data;
	}

    //编辑(后台操作)
    function edit($params, $id=0){
        if($id>0){
            // 更新条件
            $where = ['shop_id' => $id];
            $rs = $this->allowField(true)->save($params, $where);
        }else{
            // 更新数据
            $this->allowField(true)->save($params);
            $rs = $this->shop_id;
        }
        if ($rs === false) {
            $this->setError(-1, '操作失败');
            return false;
        }
        return $rs;
    }

}